<template>
  <div class="right-top-wrap">
    <Card>
      <div slot="title" class="clearfix">
        <span style="line-height:21px">可信任处理</span>
        <Button class="fr" type="primary" size="small" @click="handleSaveXr">保存</Button>
      </div>

      <div class="xr-box">
        <RadioGroup v-model="trust" size="small">
          <Radio :label="1" border>本次可信任</Radio>
          <Radio :label="2" border>持续可信任</Radio>
        </RadioGroup>
      </div>
    </Card>
  </div>
</template>
<script>
import { createNamespacedHelpers } from 'vuex'
const { mapActions, mapState } = createNamespacedHelpers('spareGas')

export default {
  name: 'spare-gas-right-top',
  data() {
    return {
      trust: 1
    }
  },
  computed: {
    ...mapState(['currentGasCls', 'currentMeterId'])
  },
  methods: {
    ...mapActions(['loadXr', 'loadTableData']),
    async handleSaveXr() {
      if (!this.currentMeterId) {
        return this.$Notice.warning({
          title: '操作提示',
          desc: '没有可操作的数据'
        })
      }
      const { code, msg } = await this.loadXr({
        trust: this.trust
      })
      if (code === 200) {
        this.$Message.success(msg)
        this.loadTableData({
          meterGasClass: this.currentGasCls
        })
      } else {
        this.$Message.error(msg)
      }
    }
  }
}
</script>
<style lang="less" scoped>
  .right-top-wrap {
    width: 100%;
    height: 100%;
    .xr-box {
      padding: 5px;
    }
  }
</style>
